package org.example.skytool.wechat.pay;


import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import com.wechat.pay.java.service.payments.model.Transaction;
import org.example.skytool.json.JackSonUtil;
import org.springframework.stereotype.Component;

/**
 * @author 22449
 */
@Component
public class WechatPayUtil {

    public WxPayResult prepareJsapiOrder(String openId, String description, Integer total, String tradeNo){
        PrepayWithRequestPaymentResponse response =JsapiService.prepayWithRequestPayment(openId,description,total,tradeNo);
        return JackSonUtil.parse(WxPayResult.class,JackSonUtil.encode(response));
    }

    public String queryOrderStatus(String tradeNo){
        Transaction transaction = JsapiService.queryOrderByOutTradeNo(tradeNo);
        String status = transaction.getTradeState().toString();
        return status;
    }

    public void closeOrder(String tradeNo){
        JsapiService.closeOrder(tradeNo);
    }


}
